package db

import (
	"fmt"

	"github.com/linclaus/stock/pkg/model"
)

type StockInfoManager interface {
	CreateStockInfo(stockInfo *model.StockInfo) error
	DeleteStockInfo(email string) error
}
type StockInfoManagerImpl struct{}

func (u *StockInfoManagerImpl) CreateStockInfo(stockInfo *model.StockInfo) error {
	_, err := engine.Insert(stockInfo)
	if err != nil {
		fmt.Printf("create StockInfo failed for reason: %s\n", err)
	}
	return err
}

func (u *StockInfoManagerImpl) GetStockInfoByNameOrCode(keyWord string) (model.StockInfo, error) {
	var stockInfo model.StockInfo
	_, err := engine.Where("name=? Or code=? Or code=? Or code=?", keyWord, keyWord, "sh"+keyWord, "sz"+keyWord).Get(&stockInfo)
	if err != nil {
		fmt.Printf("create StockInfo failed for reason: %s\n", err)
	}
	return stockInfo, err
}

var StockInfoMgr = new(StockInfoManagerImpl)
